<?php

namespace app\api\model;

use think\Model;

use app\api\model\Token;

/**
 * 商品评论模型
 */
class GoodsComment extends Model
{

    // protected $name='servers_user';

    // 开启自动写入时间戳字段
    protected $auto_timestamp = 'false';

    protected $append = ['publisher'];

    public function getCtimeAttr($value) {
        return date('Y-m-d H:i:s', $value);
    }

    public function getPublisherAttr($value, $data) {
        if (!empty($data['user_id'])){
            $user = new User();
            return $user->where('id', $data['user_id'])->where('status', 1)->field('nickname,avatar')->find();
        } else {
            return [];
        }
    }

    public function getImagesAttr($value)
    {
       if ($value) {
         return explode(',', $value);
       } else {
           return [];
       }
    }
     
}
